<?php

namespace Xrfg\Core\Trading\Account\Observers;

use Carbon\Carbon;
use Xrfg\Core\Trading\Account\Models\ContractAccount;
use Xrfg\Core\Trading\Account\Models\ContractAccountLog;

class ContractAccountObserver
{
    public function updated(ContractAccount $account)
    {
        if ($account->availableChange || $account->disabledChange) {
            $log = new ContractAccountLog();
            $log->user_id = $account->user_id;
            $log->operate_front_available = $account->getOriginal('available');
            $log->operate_front_disabled = $account->getOriginal('disabled');
            $log->operate_after_available = $account->available;
            $log->operate_after_disabled = $account->disabled;
            $log->event = $account->event;
            $log->summary = $account->summary;
            $log->created_at = Carbon::now();
            $log->updated_at = Carbon::now();
            $log->save();
        }
    }
}
